package symbols;

import inter.Id;

import java.util.Hashtable;

import lexer.Token;

public class Env {
	
	private Hashtable<String, Id> table;
	protected Env prev;
	
	public Env(Env n){
		table = new Hashtable<String, Id>();
		prev = n;
	}
	
	public void put(Token w, Id i){
		table.put(w.toString(), i);
	}
	
	public Id get(Token w){
		for( Env e = this; e != null; e = e.prev){ //itera sobre todas as tabelas armazenadas
			Id found = (Id)(e.table.get(w.toString()));
			if(found != null) return found;
		}
		return null;
	}

}
